package com.yh.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yh.javabean.Users;
import com.yh.service.UsersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
@RequestMapping("/users")
public class UsersController {
@Autowired
UsersService usersService;
@RequestMapping("/findAll")
    public String findAll(@RequestParam(value = "page",required = false,defaultValue = "1")int page,
                          @RequestParam(value = "page",required = false,defaultValue = "5")int limit,
                          HttpServletRequest request){
    PageHelper.startPage(page,limit);
    List<Users>all=usersService.findAll();
    PageInfo<Users> pageInfo=new PageInfo<>(all);
    request.setAttribute("pageInfo",pageInfo);
    return "/users/users-list";

}
    @RequestMapping(value = "/add",method = RequestMethod.GET)
    public String add(Users users ,int roleId){
    usersService.addUsers(users,roleId);
    return "redirect:/users/findAll";
    }
}
